xgetobstime ( )
{
ls *.fit >listdata
for fitfile in `cat listdata`
do
	echo $fitfile
	gethead $fitfile "burst_id" >a
	if test -s a
	then
		burstid=`cat a | awk '{print($1)}'`
		filter=`gethead $fitfile "filter"`
		output=`echo "GRB_"$burstid"_"$filter".txt"`
		mjd=`gethead $fitfile "mjd"`
		trigmjd=`gethead $fitfile "trig_mjd"`
		deltaSec=`echo $mjd $trigmjd | awk '{print(($1-$2)*86400)}'`
		exptime=`gethead $fitfile "exptime"`
		echo $deltaSec $exptime $fitfile $burstid $filter $mjd $trigmjd | column -t >>$output
	fi
done
}

xgetimggroup ( )
{
ls GRB*.txt >listtxt
for txtfile in `cat listtxt`
do
	echo $txtfile
	cat $txtfile | while read line
	do
		deltaSec=`echo $line | awk '{print($1)}'`
		fitfile=`echo $line | awk '{print($3)}'`
		buistid=`echo $line | awk '{print($4)}'`
		filter=`echo $line | awk '{print($5)}'`
		firsttxt=`echo "first_"$burstid"_"$filter".txt"`
		if test -s $firsttxt
		then
			firsttime=`cat $firsttxt`
			tt=`echo $deltaSec $firsttime | awk '{print($1-$2)}'`
			groupname=`echo "GRB_group_"$burstid"_"$filter"_"$firsttime".txt"`
			midtime=`echo $firsttime $tt | awk '{print($1+$2/2)}'`
			if [ ` echo " $tt < $midtime " | bc ` -eq 1 ]  
			then
				echo $fitfile >>$groupname
			else
				echo $midtime $groupname $firsttime $deltaSec $tt | column -t >>group.log
				echo $deltaSec >$firsttxt
			fi
		else
			echo $deltaSec >$firsttxt
		fi
	done
done

}

xgetobstime
xgetimggroup
